﻿using TechnicalIndicators.Points;
using StockModel;
using Utils;

namespace TechnicalIndicators.QuotationBased
{
	public class BidAskGenerator : GeneratorBase<Quotation, DatedSerieDoublePoint>
	{
		#region Attributes

		private bool _skipPreOpenQuotes;

		#endregion

		#region Public Methods

		public BidAskGenerator(ObservableCollection2<DatedSerieDoublePoint> destination) : base(destination)
		{
		}

		public void Configure(bool skipPreOpenQuotes)
		{
			_skipPreOpenQuotes = skipPreOpenQuotes;
		}

		protected override DatedSerieDoublePoint CreatePoint(Quotation quotation)
		{
			if (_skipPreOpenQuotes && quotation.Volume == 0)
			{
				return null;
			}
			else
			{
				return quotation.Sellers[0].Value == 0 || quotation.Buyers[0].Value == 0 ? null : new DatedSerieDoublePoint(quotation.Date, quotation.Sellers[0].Value, quotation.Buyers[0].Value);
			}
		}

		#endregion
	}
}
